﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 热更验证
{
    class MyPath
    {
        public MyPath(string path,int index)
        {
            xPath = path;
            checkKey = false;
            message= default;
            pathList = default;
            this.index = index;
        }
              
        public string[] pathList; //通用地址列表
        public string message; //错误信息
        public int index; //项目索引ID

        public string dataPath; //数据地址


        bool checkKey; //检查核心文件是否存在
        /// <summary>
        /// 获取核心文件是否存在，存在为true，不存在未false
        /// </summary>
        public bool CheckKey
        {
            get {return checkKey; }
        }

        //一级列表
        /// <summary>
        /// XML目录CheckPath
        /// </summary>
        public string xPath;
        /// <summary>
        /// 精灵属性列表 
        /// </summary>
        public string petPath;
        /// <summary>
        /// 宝箱
        /// </summary>
        public string chestPath;

        //二级列表
        /// <summary>
        /// 成长技能索引
        /// </summary>
        public string growSkillPath;
        /// <summary>
        /// 学习机索引
        /// </summary>
        public string studySkillPath;
        /// <summary>
        /// 精灵特性索引
        /// </summary>
        public string pmCharacteristicPath;
        /// <summary>
        /// 进化石返还道具 日月/决斗
        /// </summary>
        public string resetEvolutionListPath;
        /// <summary>
        /// 升星条件索引
        /// </summary>
        public string starConditionPath;
        /// <summary>
        /// 进化消耗道具索引 日月 （决斗只有M2才有进化物品消耗）
        /// </summary>
        public string evolutionConditionPath;
        /// <summary>
        /// 性格洗练条件 决斗
        /// </summary>
        public string pokeCharacterClearPath;
        /// <summary>
        /// Mega强化11级特性 决斗
        /// </summary>
        public string megaLvSysPath;
        /// <summary>
        /// 物品掉落索引 新逆袭 （0，6）
        /// </summary>
        public string dropPath;
        /// <summary>
        /// 精灵分解掉落 决斗/新喵喵
        /// </summary>
        public string disintegratePath;
        /// <summary>
        /// NPC掉落 
        /// </summary>
        public string npcListPath;
        /// <summary>
        /// 宝箱列表
        /// </summary>
        public string randomListPath;
        /// <summary>
        /// Z技能列表
        /// </summary>
        public string zMovePath;
        /// <summary>
        /// 升阶
        /// </summary>
        public string upgradeConditionPath;

        //三级列表
        /// <summary>
        /// 升星消耗道具索引
        /// </summary>
        public string starItemListPath;
        /// <summary>
        /// 升星节点消耗 决斗/新喵喵 （0，5）
        /// </summary>
        public string starContentPath;
        /// <summary>
        /// 升星材料 决斗/新喵喵 （0，3，5）
        /// </summary>
        public string starLevelCostPath;
        /// <summary>
        /// 技能Buff集合列表
        /// </summary>
        public string pmBuffListPath;

        //四级列表
        /// <summary>
        /// 种族值分配值
        /// </summary>
        public string abilityPath;
        /// <summary>
        /// 所有道具
        /// </summary>
        public string itemsPath;
        /// <summary>
        /// 所有技能
        /// </summary>
        public string pmMovePath;
        /// <summary>
        /// 所有特性
        /// </summary>
        public string pmAbilityPath;
        /// <summary>
        /// 技能Buff详细列表
        /// </summary>
        public string pmBuffPath;


        /// <summary>
        /// 设置 通用 核心文件地址
        /// </summary>
        public string[] SetPath()
        {
            //xPath = XPath;
            petPath = xPath + @"\pets.xml";
            growSkillPath = xPath + @"\growSkill.xml";
            studySkillPath = xPath + @"\studySkill.xml";
            pmCharacteristicPath = xPath + @"\pmCharacteristic.xml";
            abilityPath = xPath + @"\ability.xml";
            itemsPath = xPath + @"\items.xml";
            pmMovePath = xPath + @"\pmMove.xml";
            pmAbilityPath = xPath + @"\pmAbility.xml";
            evolutionConditionPath = xPath + @"\evolutionCondition.xml";
            starConditionPath = xPath + @"\starCondition.xml";
            dropPath = xPath + @"\drop.xml";
            npcListPath = xPath + @"\npcList.xml";
            chestPath = xPath + @"\chest.xml";
            randomListPath = xPath + @"\randomList.xml";

            string[] pathList = {
                petPath, growSkillPath, studySkillPath, pmCharacteristicPath, abilityPath,itemsPath,
                pmAbilityPath, evolutionConditionPath, starConditionPath,pmMovePath,dropPath,npcListPath,
                chestPath,randomListPath
            };

            return pathList;
        }

        /// <summary>
        /// 设置 日月 专属文件地址
        /// </summary>
        public string[] SetRiyuePath()
        {
            resetEvolutionListPath = xPath + @"\resetEvolutionList.xml"; //进化石返还
            starItemListPath = xPath + @"\starItemList.xml"; //升星材料
            zMovePath = xPath + @"\zMove.xml"; //Z技能
            pmBuffListPath = xPath + @"\pmBuffList.xml"; //技能Buff集合
            pmBuffPath = xPath + @"\pmBuff.xml"; //Buff详情

            string[] RiyuePath = { resetEvolutionListPath, starItemListPath , zMovePath , pmBuffListPath , pmBuffPath };
            return RiyuePath;
        }

        /// <summary>
        /// 设置 决斗 专属文件地址
        /// </summary>
        public string[] SetJuedouPath()
        {
            pokeCharacterClearPath = xPath + @"\pokeCharacterClear.xml"; //性格洗练
            megaLvSysPath = xPath + @"\megaLvSys.xml"; //M等级强化特性
            starContentPath = xPath + @"\starContent.xml"; //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料
            disintegratePath = xPath + @"\disintegrate.xml"; //精灵分解
            zMovePath = xPath + @"\zMove.xml"; //Z技能
            pmBuffPath = xPath + @"\pmBuff.xml"; //Buff详情

            string[] JuedouPath = { pokeCharacterClearPath, megaLvSysPath, starContentPath, starLevelCostPath, disintegratePath, zMovePath, pmBuffPath };

            return JuedouPath;
        }

        /// <summary>
        /// 设置 新喵喵 专属文件地址
        /// </summary>
        public string[] SetXinmiaomiaoPath()
        {
            starContentPath = xPath + @"\starContent.xml";  //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料
            pokeCharacterClearPath = xPath + @"\pokeCharacterClear.xml"; //性格洗练
            disintegratePath = xPath + @"\disintegrate.xml"; //精灵分解

            string[] XinmiaomiaoPath = { starContentPath, starLevelCostPath, pokeCharacterClearPath, disintegratePath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 设置 新逆袭 专属文件地址
        /// </summary>
        public string[] SetXinnixiPath()
        {
            starItemListPath = xPath + @"\starItemList.xml"; //升星材料
            zMovePath = xPath + @"\zMove.xml"; //Z技能
            pmBuffPath = xPath + @"\pmBuff.xml"; //Buff详情
            upgradeConditionPath = xPath + @"\upgradeCondition.xml"; //升阶

            string[] XinmiaomiaoPath = { starItemListPath, zMovePath, pmBuffPath , upgradeConditionPath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 设置 新世代 专属文件地址
        /// </summary>
        public string[] SetXinshidaiPath()
        {
            starContentPath = xPath + @"\starContent.xml"; //升星节点消耗
            starLevelCostPath = xPath + @"\starLevelCost.xml"; //升星材料
            zMovePath = xPath + @"\zMove.xml"; //Z技能
            pmBuffPath = xPath + @"\pmBuff.xml"; //Buff详情

            string[] XinmiaomiaoPath = { starContentPath, starLevelCostPath, zMovePath, pmBuffPath };

            return XinmiaomiaoPath;
        }

        /// <summary>
        /// 判断重要文件是否有效，正常返回true，异常返回false
        /// </summary>
        public bool CheckPath()
        {
            pathList = SetPath();
            checkKey = true;
            StringBuilder builder = new StringBuilder();
            builder.AppendLine("无效地址：");
            for (int i = 0; i < pathList.Length; i++)
            {
                if (!File.Exists(pathList[i]))
                {
                    checkKey = false;
                    builder.Append(pathList[i] + " ,");
                }
            }

            switch (index)
            {
                case 0: //日月
                    string[] riyuePath = SetRiyuePath();

                    for (int i = 0; i < riyuePath.Length; i++)
                    {
                        if (!File.Exists(riyuePath[i]))
                        {
                            checkKey = false;
                            builder.Append(riyuePath[i] + " ,");
                        }
                    }
                    break;

                case 1: //决斗
                    string[] juedouPath = SetJuedouPath();

                    for (int i = 0; i < juedouPath.Length; i++)
                    {
                        if (!File.Exists(juedouPath[i]))
                        {
                            checkKey = false;
                            builder.Append(juedouPath[i] + " ,");
                        }
                    }
                    break;

                case 2: //新喵喵
                    string[] xinmiaomiaoPath = SetXinmiaomiaoPath();

                    for (int i = 0; i < xinmiaomiaoPath.Length; i++)
                    {
                        if (!File.Exists(xinmiaomiaoPath[i]))
                        {
                            checkKey = false;
                            builder.Append(xinmiaomiaoPath[i] + " ,");
                        }
                    }
                    break;

                case 3: //新逆袭
                    string[] xinnixiPath = SetXinnixiPath();

                    for (int i = 0; i < xinnixiPath.Length; i++)
                    {
                        if (!File.Exists(xinnixiPath[i]))
                        {
                            checkKey = false;
                            builder.Append(xinnixiPath[i] + " ,");
                        }
                    }

                    break;

                case 4: //新世代
                    string[] xinshidaiPath = SetXinshidaiPath();

                    for (int i = 0; i < xinshidaiPath.Length; i++)
                    {
                        if (!File.Exists(xinshidaiPath[i]))
                        {
                            checkKey = false;
                            builder.Append(xinshidaiPath[i] + " ,");
                        }
                    }

                    break;

                case 5: //通用类型日月
                    string[] koudaiPath = SetRiyuePath();

                    for (int i = 0; i < koudaiPath.Length; i++)
                    {
                        if (!File.Exists(koudaiPath[i]))
                        {
                            checkKey = false;
                            builder.Append(koudaiPath[i] + " ,");
                        }
                    }
                    break;
            }

            if (!checkKey)
            {
                message = builder.ToString();
            }
            
            return checkKey;
        }
    }
}
